#define  _CRT_SECURE_NO_WARNINGS
class Solution {
    int ret;
    vector<bool> jug;
    void dfs(int n, int index = 1)
    {
        if (index > n)
        {
            ret++;
            return;
        }
        for (int num = 1; num <= n; num++)
        {
            if (jug[num])
            {
                if (num % index == 0 || index % num == 0)
                {
                    jug[num] = false;
                    dfs(n, index + 1);
                    jug[num] = true;
                }
            }
        }
    }

public:
    int countArrangement(int n) {
        jug.resize(n + 1, true);
        dfs(n);
        return ret;
    }
};